package com.example.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.base.ResultBaseController;
import com.example.entity.SpuComment;
import com.example.entity.User;
import com.example.param.SearchAndOrder;
import com.example.service.SpuCommentService;
import com.example.vo.Result;
import com.example.vo.admin.AdminCommentVo;
import com.example.vo.comment.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: aimi
 * @Create: 2024-05-28
 **/
@RestController
@Slf4j
@RequestMapping("/admin/comment")
public class AdminCommentController extends ResultBaseController<SpuCommentService, SpuComment> {
    @Autowired
    private SpuCommentService spuCommentService;

    @Operation(summary = "管理员获取评论分页")
    @GetMapping("/getCommentPage")
    public Result<PageResult<AdminCommentVo>> getCommentPage(@RequestParam(defaultValue = "1") Integer pageNo,
                                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                                             String keyword){
        log.info("管理员获取评论分页pageNo：{}，pageSize：{} keyword：{}",pageNo,pageSize,keyword);
        PageResult<AdminCommentVo> pageResult = spuCommentService.getCommentPage(pageNo,pageSize,keyword);
        return Result.ok(pageResult);
    }

    @PutMapping("/updateStatus/{id}")
    public Result<Boolean> updateStatus(@PathVariable Integer id){
        SpuComment spuComment = baseService.getById(id);
        if(spuComment != null){
            spuComment.setStatus(!spuComment.isStatus());
        }
        baseService.updateById(spuComment);
        return Result.ok();
    }
}